/*
 * @Descripttion:
 * @Author: LiBiwei
 * @Date: 2025-03-16 13:32:28
 * @LastEditors: LiBiwei
 * @LastEditTime: 2025-03-16 14:20:43
 */
import { store } from "@/store";
import GoodsAPI from "@/api/goods/goods";

export const useActivityGoodsStore = defineStore("goods", () => {
  const list = ref([]);

  const loading = reactive({
    list: false,
    create: false,
    detail: false,
    update: false,
    delete: false,
  });

  async function fetchActivityList(query: any) {
    loading.list = true;
    const response = await GoodsAPI.activityList(query);
    loading.list = false;
    if (response) {
      list.value = response;
      return response;
    }
  }

  async function fetchAddActivity(data: any) {
    loading.create = true;
    const response = await GoodsAPI.addActivity(data);
    loading.create = false;
    if (response) {
      return response;
    }
  }

  async function fetchActivityDetail(id: number | string) {
    loading.detail = true;
    const response = await GoodsAPI.activityDetail(id);
    loading.detail = false;
    if (response) {
      return response;
    }
  }

  return {
    list,
    loading,
    fetchActivityList,
    fetchAddActivity,
    fetchActivityDetail,
  };
});

export default function useActivityGoodsStoreHook() {
  return useActivityGoodsStore(store);
}
